package dryven.util.json.dryvenjson.encoders;

import java.io.IOException;

import dryven.model.di.LocalThreadStorage;
import dryven.util.json.JsonEncoder;
import dryven.util.json.dryvenjson.FieldPolicy;
import dryven.util.json.dryvenjson.JSONCompositeEncoder;
import dryven.util.json.dryvenjson.JSONTypeEncoder;

public class BooleanEncoder implements JSONTypeEncoder {

	@Override
	public void encodeValue(Object value, JSONCompositeEncoder e, FieldPolicy p, LocalThreadStorage diStorage, Appendable dest) throws IOException {
		Boolean b = (Boolean)value;
		dest.append(b.booleanValue()?"true":"false"); 
	}

	@Override
	public boolean isApplicableForType(Class<?> type) {
		return type==Boolean.TYPE || type==Boolean.class;
	}

}
